<?

if($this->input->get('logout')=='1'){
	$this->session->delete('clientid');	
}



echo '<div class="clientlogin_form">';

$client=ORM::factory('client', $this->session->get('clientid'));


if($client->id!=0){
	echo '<h1>logged in as '.$client->title.'</h1>';
	echo html::anchor($this->uri->string().'?logout=1','logout');
}else{
	
	if($this->input->post('username')!=''){	
		$clientid=$client->login($this->input->post('username'),$this->input->post('password'));
		$this->session->set('clientid',$clientid);
		unset($_POST);
		url::redirect($this->uri->string());
	}
	
	echo form::open();
	echo '<p>';
	echo form::label('username', 'Username');
	echo form::input('username');
	echo '</p>';
	echo '<p>';
	echo form::label('password', 'Password');
	echo form::password('password');
	echo '</p>';
}

echo '</div>';
?>